Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | import { apiService } from './api';
import { ApiResult } from '@/types';
import { ContentType } from '@/types';
export interface TMDBSearchResult {
id: number;
title: string;
overview?: string;
release_date?: string;
poster_url?: string;
backdrop_url?: string;
vote_average?: number;
media_type?: string;
year?: number;
}
export interface TMDBMovieDetails {
id: number;
title: string;
overview: string;
release_date: string;
poster_path?: string;
backdrop_path?: string;
vote_average: number;
runtime?: number;
genres: Array<{ id: number; name: string }>;
production_companies: Array<{ id: number; name: string }>;
imdb_id?: string;
}
export interface TMDBTVDetails {
id: number;
name: string;
overview?: string;
poster_url?: string;
backdrop_url?: string;
first_air_date?: string;
last_air_date?: string;
year?: number;
number_of_seasons: number;
number_of_episodes: number;
vote_average: number;
vote_count: number;
seasons: Array<{
id: number;
season_number: number;
episode_count: number;
name: string;
overview?: string;
poster_path?: string;
air_date?: string;
}>;
}
export interface TMDBSeasonDetails {
id: number;
season_number: number;
name: string;
overview: string;
poster_path?: string;
air_date?: string;
episodes: Array<{
id: number;
episode_number: number;
name: string;
overview: string;
still_path?: string;
air_date?: string;
runtime?: number;
vote_average: number;
}>;
}
class TMDBService {
/**
* Search for content on TMDB
*/
async searchContent(query: string, contentType: ContentType): Promise<ApiResult<TMDBSearchResult[]>> {
try {
// For series and anime, search TV shows; for movies, search movies
const searchType = (contentType === ContentType.SERIES || contentType === ContentType.ANIME) ? 'tv' : 'movie';
const result = await apiService.get<{ results: TMDBSearchResult[]; tmdb_available: boolean }>('/api/tmdb/search', {
params: {
q: query,
search_type: searchType
}
});
if (result.success) {
return {
success: true,
data: result.data.results
};
}
return result as ApiResult<TMDBSearchResult[]>;
} catch {
return {
success: false,
error: {
error: 'TMDB Search Failed',
details: 'Failed to search TMDB content',
timestamp: new Date().toISOString()}
};
}
}
/**
* Search by TMDB ID
*/
async searchById(tmdbId: number, contentType: ContentType): Promise<ApiResult<TMDBSearchResult>> {
try {
const endpoint = contentType === ContentType.VOD ? 'movie' : 'tv';
const result = await apiService.get<TMDBSearchResult>(`/api/tmdb/${endpoint}/${tmdbId}`);
return result;
} catch {
return {
success: false,
error: {
error: 'TMDB ID Search Failed',
details: 'Failed to fetch content by TMDB ID',
timestamp: new Date().toISOString()}
};
}
}
/**
* Get detailed movie information
*/
async getMovieDetails(tmdbId: number): Promise<ApiResult<TMDBMovieDetails>> {
try {
const result = await apiService.get<TMDBMovieDetails>(`/api/tmdb/movie/${tmdbId}`);
return result;
} catch {
return {
success: false,
error: {
error: 'Movie Details Failed',
details: 'Failed to fetch movie details from TMDB',
timestamp: new Date().toISOString()}
};
}
}
/**
* Get detailed TV series information
*/
async getTVDetails(tmdbId: number): Promise<ApiResult<TMDBTVDetails>> {
try {
const result = await apiService.get<TMDBTVDetails>(`/api/tmdb/tv/${tmdbId}`);
return result;
} catch {
return {
success: false,
error: {
error: 'TV Details Failed',
details: 'Failed to fetch TV series details from TMDB',
timestamp: new Date().toISOString()}
};
}
}
/**
* Get season details with episodes
*/
async getSeasonDetails(tmdbId: number, seasonNumber: number): Promise<ApiResult<TMDBSeasonDetails>> {
try {
const result = await apiService.get<TMDBSeasonDetails>(`/api/tmdb/tv/${tmdbId}/season/${seasonNumber}`);
return result;
} catch {
return {
success: false,
error: {
error: 'Season Details Failed',
details: 'Failed to fetch season details from TMDB',
timestamp: new Date().toISOString()}
};
}
}
/**
* Test TMDB API key
*/
async testApiKey(apiKey: string): Promise<ApiResult<{ valid: boolean; message: string }>> {
try {
const result = await apiService.post<{ valid: boolean; message: string }>('/api/admin/config/tmdb/test', {
tmdb_api_key: apiKey
});
if (result.success) {
return {
success: true,
data: {
valid: result.data.valid,
message: result.data.message
}
};
}
return result as ApiResult<{ valid: boolean; message: string }>;
} catch {
return {
success: false,
error: {
error: 'API Key Test Failed',
details: 'Failed to test TMDB API key',
timestamp: new Date().toISOString()}
};
}
}
/**
* Get trending content
*/
async getTrending(mediaType: 'movie' | 'tv' | 'all' = 'all', timeWindow: 'day' | 'week' = 'week'): Promise<ApiResult<TMDBSearchResult[]>> {
return {
success: false,
error: {
error: 'Trending Content Unavailable',
details: 'Backend does not expose a trending TMDB endpoint.',
timestamp: new Date().toISOString()}
};
}
/**
* Get popular content
*/
async getPopular(mediaType: 'movie' | 'tv'): Promise<ApiResult<TMDBSearchResult[]>> {
return {
success: false,
error: {
error: 'Popular Content Unavailable',
details: 'Backend does not expose a popular TMDB endpoint.',
timestamp: new Date().toISOString()}
};
}
/**
* Get content by genre
*/
async getByGenre(mediaType: 'movie' | 'tv', genreId: number): Promise<ApiResult<TMDBSearchResult[]>> {
return {
success: false,
error: {
error: 'Genre Content Unavailable',
details: 'Backend does not expose a genre TMDB endpoint.',
timestamp: new Date().toISOString()}
};
}
/**
* Get available genres
*/
async getGenres(mediaType: 'movie' | 'tv'): Promise<ApiResult<Array<{ id: number; name: string }>>> {
return {
success: false,
error: {
error: 'Genres Unavailable',
details: 'Backend does not expose a TMDB genres endpoint.',
timestamp: new Date().toISOString()}
};
}
/**
* Check TMDB API status
*/
async getStatus(): Promise<ApiResult<{ available: boolean; message: string }>> {
try {
const result = await apiService.get<{ available: boolean; message: string }>('/api/tmdb/status');
return result;
} catch {
return {
success: false,
error: {
error: 'TMDB Status Check Failed',
details: 'Failed to check TMDB API status',
timestamp: new Date().toISOString()}
};
}
}
/**
* Get image configuration
*/
async getImageConfig(): Promise<ApiResult<{
base_url: string;
secure_base_url: string;
poster_sizes: string[];
backdrop_sizes: string[];
}>> {
return {
success: false,
error: {
error: 'Image Config Unavailable',
details: 'Backend does not expose a TMDB configuration endpoint.',
timestamp: new Date().toISOString()}
};
}
/**
* Helper method to get the correct search endpoint based on content type
*/
private getSearchEndpoint(contentType: ContentType): string {
switch (contentType) {
case ContentType.VOD:
return 'movie';
case ContentType.SERIES:
case ContentType.ANIME:
return 'tv';
case ContentType.KIDS:
return 'multi'; // Search both movies and TV
default:
return 'multi';
}
}
/**
* Helper method to build full image URL
*/
buildImageUrl(path: string, size: 'w92' | 'w154' | 'w185' | 'w342' | 'w500' | 'w780' | 'original' = 'w500'): string {
if (!path) return '';
return `https://image.tmdb.org/t/p/${size}${path}`;
}
/**
* Helper method to build full backdrop URL
*/
buildBackdropUrl(path: string, size: 'w300' | 'w780' | 'w1280' | 'original' = 'w1280'): string {
if (!path) return '';
return `https://image.tmdb.org/t/p/${size}${path}`;
}
}
export const tmdbService = new TMDBService();
|